<?php
    
    /**
     * LeafPHP默认创建的action操作类，测试使用
     */
    class indexController extends controller {

        public function index (){
            
            echo '欢迎使用LeafPHP框架 ^_^';
            //$userDao = $this->userDao;
            /*$i = 1;
            $sql = "insert into leaf_user(name) values('wangwu')";
            $res = $this->db->insert($sql);
            P($res);*/

            //$sql = "select name from leaf_user order by id desc";
            //$res = $this->db->fetchRow($sql, null);
            //$res = $this->getDb()->fetchRow($sql);
            //$db  = $this->getDb();
            //$res = $db->fetchAll($sql);
            //P($res);
            //$url = U('index/index',array('ss'=>'dd','qq'=>'pp'));
            //P($url);
            $url = U('index/index', 'ss=1&jj=dsds');
            P($url);
            P($_SERVER['PATH_INFO']);
            /*$sql = "update leaf_user set name=:name";
            $data = array(':name'=>'lisi');
            $res = $this->db->update($sql, $data);
            P($res);*/

            /*try{
                $sql = "insert into leaf_user(name) values(:wangwu)";
                $db  = $this->getDb();
                $db->transaction();
                $db->prepare($sql);
                for ($i=1; $i <= 1000; $i++) { 
                    $data = array(':wangwu'=>'wangwu'.$i);
                    $db->execute($data);
                    //调用db类的异常方法，这种方式无需再catch块中写$db->rollBack()
                    if($i>=500) $db->exception();
                }
                $db->commit();
            }catch(exception $e){
                echo $e->getMessage();
            }*/

            /*try{
                $sql = "insert into leaf_user(name) values(:wangwu)";
                $db  = $this->getDb();
                $db->transaction();
                $db->prepare($sql);
                for ($i=1; $i <= 2; $i++) { 
                    $data = array(':wangwu'=>'wangwu'.$i);
                    $db->execute($data);
                    if($i>=1000){
                        //手动抛出异常，这种方式还需要再catch块中手动写$db->rollBack()
                        throw new Exception("nimei!", 1);
                    }
                }
                $db->commit();
            }catch(exception $e){
                echo $e->getMessage();
                $db->rollBack();
            }*/
            //$db->rollBack();*/

            /*$sql = 'insert into leaf_user(name) values(\'dsdsdsd\')';
            $res = $this->getDb()->prepare($sql)->execute()->insert();
            P($res);*/

            //存储过程使用
            /*$sql = 'call addName(\'nimei\')';
            $res = $this->getDb()->prepare($sql)->execute()->fetchColumn();
            //$res = $this->getDb()->fetchAll($sql);
            P($res);

            $sql = 'call getNames(3000)';
            $res = $this->getDb()->prepare($sql)->execute()->fetchAll();
            //$res = $this->getDb()->fetchAll($sql);
            P($res);*/

            //分页
            $sql = 'select * from leaf_user order by id desc';
            $data = null;
            $res = $this->getDb()->fetchPage($sql, $data, 3);
            P($res);

            ###等待测试分布式！！！！！

        }

    }